<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      padding: 0;
      margin: 0;
    }

    .w {
      /* 版心 */
      /* width: 1126px; */
      width: 1226px;
      margin: 0 auto;
    }

    html {
      scroll-behavior: smooth;
    }

    .header {
      height: 200px;
      background: grey;
    }

    .navAll {
      height: 45px;

    }

    .wrapNav {
      width: 100%;
      background-color: grey;
      /*
            了解 
            粘性定位:  吸顶效果的
                (1) 盒子顶部没有移出 窗口(包裹该盒子的父元素)之前,标准文档流,移出之后会变为固定定位
            */
      /* position:sticky;
            top: 0;
            left: 0; */
    }


    .nav {
      background: pink;
      height: 45px;
    }

    .banner {
      height: 300px;
      background-color: red;
    }

    .main .part {
      height: 400px;
      line-height: 400px;
      text-align: center;
      border: 1px solid #333;
    }

    .footer {
      height: 500px;
      background-color: grey;
    }

    .tips {
      width: 100%;
      line-height: 45px;
      text-align: center;
      background-color: rgba(125, 255, 255, 0.6);
      position: fixed;
      bottom: 0;
      left: 0;
      display: none;
    }
  </style>
</head>

<body>
  <!--  -->
  <div class="header w"></div>
  <div class="wrapNav">
    <div class="navAll">
      <div class="nav w">
        <!-- 锚链接 -->
        <a href="#live">直播</a>
        <a href="#ani">动画</a>
        <a href="#drama">番剧</a>
        <a href="#chAni">国漫</a>
        <a href="#music">音乐</a>
        <a href="#sports">运动</a>
        <!--  # 默认返回当前页面的顶部 -->
        <a href="#">返回顶部</a>

        <!-- a 默认跳转当前页  => 刷新页面 -->
        <a href="">刷新</a>
      </div>
    </div>
  </div>
  <div class="banner w"></div>
  <div class="main w">
    <!-- 锚标记 -->
    <div id="live" class="part">直播</div>
    <div id="ani" class="part">动画</div>
    <div id="drama" class="part">番剧</div>
    <div id="chAni" class="part">国漫</div>
    <div id="music" class="part">音乐</div>
    <div id="sports" class="part">运动</div>
  </div>
  <div class="footer w"></div>
  <div class="tips">到达底部</div>
</body>
<script>
  // 1. 导航栏吸顶效果
  // 2. 判断滚动条是否到达底部  =>显示tips  0.5s后消失

  // 文档的可视宽高
  // 文档的实际宽高
  // 滚动条距离页面顶部的位置
  var nav = document.querySelector('.wrapNav')
  var tips = document.querySelector('.tips')
  // console.log(nav);
  window.onscroll = function () {
    var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
    // console.log('scrollTop:' + scrollTop);
    if (scrollTop >= 150) {
      nav.style.position = 'fixed';
      nav.style.top = '0';

    } else {
      nav.style.position = 'static'
    }

    var clientHeight = document.documentElement.clientHeight || document.body.clientHeight;
    console.log('clientHeight:' + clientHeight);
    var scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
    console.log('scrollHeight:' + scrollHeight);
    var scrollMax = scrollHeight - clientHeight;

    if (scrollTop >= scrollMax && scrollTop <= scrollMax + 1) {
      tips.style.display = 'block';
      setTimeout(function () {
        tips.style.display = "none";
      }, 500);
    }
  }


</script>

</html>